// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================
package tc.map;

import java.awt.Point;
import java.lang.Math;

//=============================================================================
/** 2d vector partial implementation.
*/
public class Tc2dVector {
//=============================================================================	
public double x;
public double y;
//=============================================================================	
public Tc2dVector(double x, double y) {
	this.x = x;
	this.y = y;
}

public Tc2dVector(Point from, Point to) {
	this.x = to.x - from.x;
	this.y = to.y - from.y;
}

public double sizeSquare()	{
	return x*x + y*y;
}

public double size() {
	return Math.sqrt(sizeSquare());
}

public void multiply(double arg) {
	x *= arg;
	y *= arg;
}

public void normalize() {
	multiply(1.0/size());
}

public Tc2dVector perpendLeft() {
	return new Tc2dVector(-y , x);
}

public Tc2dVector perpendRight() {
	return new Tc2dVector( y, -x );
}

public void setSize(double size) {
	normalize();
	multiply(size);
}

public void addTo(Point pt) {
	pt.x += x;
	pt.y += y;
}
//=============================================================================
}
